package com.emep.changzhi.analyse.http.statistics;


import com.emep.changzhi.analyse.model.ResultBean;
import com.emep.changzhi.analyse.service.statistics.GetDayAqiService;
import com.emep.changzhi.analyse.utils.Constant;
import com.emep.changzhi.analyse.utils.DataValidator;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("stat")
@Api(value="api统计服务",tags={"统计指定站点指定时间范围的获取站点内污染物的值"})
public class GetDayAqiController {
    @Autowired
    private GetDayAqiService getDayAqiService;


    @ApiOperation(value="根据时间查询国控站点6参数", notes="根据起始时间和国控站点名称来获取6参数信息")
    @ApiResponses({ @ApiResponse(code = 1, message = "操作成功"),
            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303, message = "权限不足") })

    @GetMapping(value = "site/pollution")
    public ResultBean<Map<String,Object>>  findapiByTime(@RequestParam Map<String, Object> payload){
        ResultBean result = DataValidator.validateMapData(payload);
        if (result.getCode() == Constant.RESULT_CODE_SUCCESS) {
            return  result.ok(getDayAqiService.findapiByTime(payload));
        }

        return  result;
    }


    @ApiOperation(value="根据时间查询国控站点6参数", notes="根据起始时间和国控站点名称来获取6参数信息")
    @ApiResponses({ @ApiResponse(code = 1, message = "操作成功"),
            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303, message = "权限不足") })

    @GetMapping(value = "site/getaqinum")
    public ResultBean<Map<String,Object>>  getaqinum(@RequestParam Map<String, Object> payload){
        ResultBean result = DataValidator.validateMapData(payload);
        //城市名称
        String siteName = payload.get("siteName") != null ? payload.get("siteName").toString():"" ;
        //开始时间
        String pollution = payload.get("pollution")!= null ? payload.get("pollution").toString():"";
        //结束时间
        String startime = payload.get("startime")!= null ? payload.get("startime").toString():"";
           //结束时间
        String endtime = payload.get("endtime")!= null ? payload.get("endtime").toString():"";


        if (result.getCode() == Constant.RESULT_CODE_SUCCESS) {
            return  result.ok(getDayAqiService.getaqinum(siteName,pollution,startime,endtime));
        }

        return  result;
    }
}
